package com.zzx.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzx.domain.GoodsPics;
import com.zzx.domain.Vo.GoodsPicsVo;
import com.zzx.mapper.GoodsPicsMapper;
import com.zzx.service.GoodsPicsService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 商品-相册关联表(GoodsPics)表服务实现类
 *
 * @author makejava
 * @since 2022-08-02 14:07:18
 */
@Service("goodsPicsService")
public class GoodsPicsServiceImpl extends ServiceImpl<GoodsPicsMapper, GoodsPics> implements GoodsPicsService {

    /**
     * 通过商品id获取图片
     * @param goodsId
     * @return
     */
    @Override
    public List<GoodsPicsVo> getGoodsPicsByGoodsId(Long goodsId) {
        LambdaQueryWrapper<GoodsPics> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(GoodsPics::getGoodsId,goodsId);
        List<GoodsPics> list = list(wrapper);
        List<GoodsPicsVo> collect = list.stream().map(item ->
            new GoodsPicsVo(item.getPicsId(), item.getGoodsId(), item.getPicsBig(), item.getPicsMid(), item.getPicsSma())
        ).collect(Collectors.toList());
        return collect;
    }
}

